package v1

import (
	"gitee.com/CrazyMage/lite-note/internal/controller/http/middleware"
	"gitee.com/CrazyMage/lite-note/internal/service"
	"gitee.com/CrazyMage/lite-note/pkg/logger"
	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
)

func NewUserRoutes(apiV1Group *gin.RouterGroup, t service.User, l logger.Interface) {
	r := &V1{t: t, l: l, v: validator.New(validator.WithRequiredStructEnabled())}

	//公共路由
	publicGroup := apiV1Group.Group("/user")
	{
		publicGroup.POST("/login", r.loginHandler)
		publicGroup.POST("/register", r.registerHandler)
	}

}

func NewNoteRoutes(apiV1Group *gin.RouterGroup, n service.Note, l logger.Interface) {
	r := &V1{n: n, l: l, v: validator.New(validator.WithRequiredStructEnabled())}

	protectedGroup := apiV1Group.Group("/note")
	protectedGroup.Use(middleware.JWTAuth())
	{
		protectedGroup.POST("/create", r.CreateNoteHandler)
		protectedGroup.DELETE("/del/:id", r.DeleteNoteHandler)
		protectedGroup.PUT("/update", r.UpdateNoteHandler)
		protectedGroup.GET("/list", r.ListNoteHandler)
		protectedGroup.GET("/show/:id", r.ShowNoteHandler)
		protectedGroup.GET("/search", r.SearchNoteHandler)
	}
}
